package com.bokee.archerwq.lab.mina.codec;

import org.apache.mina.common.ByteBuffer;
import org.apache.mina.common.IoSession;
import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
import org.apache.mina.filter.codec.ProtocolEncoderOutput;

import com.bokee.archerwq.lab.mina.message.Response;

public class ResponseEncoder extends ProtocolEncoderAdapter {

	@Override
	public void encode(IoSession session, Object message,
			ProtocolEncoderOutput out) throws Exception {
		Response response = (Response) message;
		ByteBuffer buffer = ByteBuffer.allocate(24, false);
		buffer.put(response.getReqId().getBytes());
		buffer.put(response.getDateTime().getBytes());
		buffer.flip();
		out.write(buffer);
		out.flush();
	}

}
